import java.io.*;
import java.text.*;
import java.util.*;


public class ParserControl {

	Vector<HandParser> parser=new Vector<HandParser>();
	String output="data.csv";

	public void AddParser(HandParser ez)
	{
		parser.add(ez);
	}

	public void setOutput(String output) {
		this.output = output;
	}

	public ArrayList<GameInfo> Perform()
	{
		ArrayList<GameInfo> eredmeny=new ArrayList<GameInfo>();
		FileWriter ops=null;
		try {
			ops = new FileWriter(output,false);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		BufferedWriter out=new BufferedWriter(ops);
		
		try {
			out.write("Date;buy-in;fee;players;finishing;winnigs;duration;gamenumber;room\n");
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		for(HandParser hp: parser)
		{
			ArrayList<GameInfo> gal=hp.Reader();
			eredmeny.addAll(gal);
			for(GameInfo g: gal)
			{
				SimpleDateFormat sdf1= new SimpleDateFormat("yyyy/M/dd");
				SimpleDateFormat sdf2= new SimpleDateFormat("m");
				try {
					out.write(sdf1.format(new java.util.Date(g.date.getTimeInMillis()))+";"
							+g.buyin+";"
							+g.rake+";"
							+g.players+";"
							+g.finishing+";"
							+g.winnings+";"
							+sdf2.format(new java.util.Date(g.duration.getTimeInMillis()))+";"
							+g.gamenum+";"
							+hp.getName()+"\n");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
		try {
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return eredmeny;
	}
}
